<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Watch 选项 监控数据</title>
    <script src="../assets/js/vue.js"></script>
</head>
<body>
    <h1>Watch 选项 监控数据</h1>
    <hr>
    <div id="app">
        <p>今日温度：{{wendu}}</p>
        <P>穿衣建议：{{suggestion}}</P>
        <div>
            <button @click="add()">增加温度</button>
            <button @click="del()">降低温度</button>
        </div>
    </div>
</body>
<script>
    var chuanyiArray = ['穿T恤短袖','穿夹克长裙','穿棉衣羽绒服'];
    var app = new Vue({
        el:"#app",
        data:{ 
            wendu:12,
            suggestion:'穿夹克长裙'
        },
        methods:{
            add(){
                this.wendu+=5;
            },
            del(){
                this.wendu-=5;
            }
        },
        // watch:{
        //     wendu:function(newVal,oldVal){
        //         if(newVal>=26){
        //             this.suggestion=chuanyiArray[0]
        //         }else if(newVal<26 && newVal >=0){
        //             this.suggestion=chuanyiArray[1]
        //         }else{
        //             this.suggestion=chuanyiArray[2]
        //         }
        //     }
        // }
    })
    //用实例监控
    app.$watch("wendu",function(newVal,oldVal){
        if(newVal>=26){
            this.suggestion=chuanyiArray[0]
        }else if(newVal<26 && newVal >=0){
            this.suggestion=chuanyiArray[1]
        }else{
            this.suggestion=chuanyiArray[2]
        }
    })
</script>
</html>